<template>
	<div>
		<HomeHeader></HomeHeader>
		<HomeLeft :cur="2"></HomeLeft>
		<div id="main">
			<div id="web_con">
				<div class="web_wp">
					<div class="web_location">
						<div class="here_area">
							<strong>当前位置：</strong>用户管理&nbsp;&nbsp;»&nbsp;&nbsp;添加
						</div>
						<div class="here_btn">
							<a href="javascript:history.back()" class="web_btn btn_add"><em
									class="iconfont icon-shdcfanhui"></em>返回</a>
						</div>
					</div>

					<div class="tabTitle">
						<ul class="clearfix">
							<li class="cur"><a href="javascript:;">基本信息</a></li>
						</ul>
						<div class="tabCont">
							<div class="cont">
								<table class="dataTable">
									<tr>
										<td class="ltd">所属商户</td>
										<td class="rtd">											
											<select class="select" v-model="merchantno">
												<option value="0">请选择</option>
												<option v-for="(item,i) in listinfo" :key="i" :value="item.merchantno">{{item.name}}</option>
											</select>											
											<!-- <input type="text" v-model="merchantno" class="input-text"> -->
											<span class="text-red pl10">必填</span>
										</td>
									</tr>
									<tr>
										<td class="ltd">姓名</td>
										<td class="rtd">
											<input type="text" v-model="nickname" class="input-text">
											<span class="text-red pl10">必填</span>
										</td>
									</tr>
									<tr>
										<td class="ltd">手机号</td>
										<td class="rtd">
											<input type="text" v-model="phone" class="input-text">
											<span class="text-red pl10">必填</span>
										</td>
									</tr>
									<tr>
										<td class="ltd">身份证号</td>
										<td class="rtd">
											<input type="text" v-model="idcard" class="input-text">
											<span class="text-red pl10">必填</span>
										</td>
									</tr>
									<tr>
										<td class="ltd">开户行</td>
										<td class="rtd">
											<input type="text" v-model="bankname" class="input-text">
										</td>
									</tr>
									<tr>
										<td class="ltd">银行卡账号</td>
										<td class="rtd">
											<input type="text" v-model="cardno" class="input-text">
										</td>
									</tr>
									<tr>
										<td class="ltd">持卡人</td>
										<td class="rtd">
											<input type="text" v-model="owner" class="input-text">
										</td>
									</tr>

									<tr>
										<td class="ltd">用户名</td>
										<td class="rtd">
											<input type="text" :value="phone" disabled class="input-text">
										</td>
									</tr>
									<tr>
										<td class="ltd">密码</td>
										<td class="rtd">
											<input type="text" class="input-text">
											<span class="text-red pl10">必填</span>
										</td>
									</tr>
									
									<tr>
										<td class="ltd">存入金额</td>
										<td class="rtd">
											<input type="number" class="input-text">
											<span class="text-red pl10">必填</span>
										</td>
									</tr>
									<tr>
										<td class="ltd">生效日期</td>
										<td class="rtd">
											<el-date-picker v-model="value1" type="date" placeholder="选择日期">
											</el-date-picker>
											<span class="text-red pl10">必填</span>
										</td>
									</tr>
								</table>
							</div>
						</div>
						<div>
							<div class="contBtn">
								<table class="dataTable">
									<tfoot>
										<tr>
											<td class="ltd"></td>
											<td class="rtd">
												<a href="javascript:;" class="web_btn btn_add" @click="SubMit()">
													<em class="iconfont icon-shdcbaocun"></em>保存
												</a>
											</td>
										</tr>
									</tfoot>
								</table>
							</div>
						</div>
					</div>
				</div>

			</div>
		</div>
	</div>
</template>

<script>
	import HomeHeader from '../components/Header.vue';
	import HomeLeft from '../components/Left.vue';
	import PicUp from '../components/PicUp.vue'
	export default {
		components: {
			HomeHeader,
			HomeLeft,
			PicUp
		},
		data() {
			return {
				merchantno:'0',
				idcard: '', //身份证号
				phone: '', //手机号
				nickname: '', //用户名
				cardno: '',
				bankname: '',
				owner: '',
				password: '',
				value1:'',
				value2:'',
				listinfo:[],
			}
		},
		onLoad(e) {
			let that = this;
			that.GetShopList()
		},
		methods: {
			
			GetShopList: function() {
				let that = this;
				uni.showLoading({
					title: '加载中...',
					mask: true
				});
				let _data = {
				};
				that.common.http('GET', 'merchant', _data, function(res) {
					uni.hideLoading();
					console.log(res.data)
					that.listinfo = res.data
				});
			},
			
			
			//保存
			SubMit: function() {
				let that = this;
				if (that.name == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入名称',
						duration: 2000
					});
				} else if (that.sort == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入排序',
						duration: 2000
					});
				} else {
					let _data = {
						name: that.name,
						sort: that.sort
					}
					if (that.id > 0) {
						that.common.http('POST', 'addr/' + that.id + '/update', _data, function(res) {
							uni.hideLoading();
							uni.showToast({
								icon: 'none',
								title: '修改成功！',
								duration: 2000
							});
							setTimeout(function() {
								that.navigateBack();
							}, 1500);
						});
					} else {
						that.common.http('POST', 'addr/store', _data, function(res) {
							uni.hideLoading();
							uni.showToast({
								icon: 'none',
								title: '添加成功',
								duration: 2000
							});
							setTimeout(function() {
								that.navigateBack();
							}, 1500);
						});
					}
				}
			},

			navigateBack() {
				// #ifdef H5
				const pages = getCurrentPages()
				if (pages.length > 1) {
					uni.navigateBack(1)
					return;
				}
				//使用vue-router返回上一级
				let a = this.$router.go(-1)
				if (a == undefined) {}
				return;
				// #endif
				uni.navigateBack();
			},

		}
	}
</script>

<style>


</style>